package com.lanou.zakerproject.hotspot;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.lanou.zakerproject.R;
import com.lanou.zakerproject.db.DbTool;

/**
 * Created by dllo on 16/1/15.
 */
public class HotSpotHobbyFragment extends Fragment {
    private GridView gridView;
    private HostspotLikeAdapter hostspotLikeAdapter;
    private DbTool dbTool;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_hotspothobby, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        gridView = (GridView) view.findViewById(R.id.gridView_itemhobby);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        hostspotLikeAdapter = new HostspotLikeAdapter(getActivity());
        dbTool = new DbTool(getActivity());
        gridView.setAdapter(hostspotLikeAdapter);
        hostspotLikeAdapter.update(dbTool.allData());
        gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                hostspotLikeAdapter.delData(position);
                return false;
            }
        });
    }
}
